package com.yt.ds.chapter2;

import com.yt.ds.util.SortUtil;

/**
 * @Author: lzf
 * @Date: 2020/7/10 18:00
 * @Description: 插入排序
 */
public class InsertionSort implements Sort {
    @Override
    public Comparable[] sort(Comparable[] array) {
        for (int i = 1; i < array.length; i++) {
            for (int k = i; k > 0 && array[k].compareTo(array[k - 1]) < 0; k--) {
                SortUtil.exch(array, k, k - 1);
            }
        }
        return array;
    }
}
